package com.kevin.design.structuralPattern.decorator;

/**
 * @Description java
 * @Author Kevin
 * @Date: Created in  15:55 2019/11/6:
 * @Modified By:
 * @Email: tang.lx@topcheer.com
 */
public class DecoratorTest {
    public static void main(String[] args) {
        new FoodD2(new Food1()).eat();
    }
}

abstract class Food {
    abstract void eat();
}

class Food1 extends Food {

    @Override
    public void eat() {
        System.out.println(1);
    }
}

class Food2 extends Food {

    @Override
    public void eat() {
        System.out.println(2);
    }
}

class FoodD1 extends Food1 {
    Food food;

    public FoodD1(Food food) {
        this.food = food;
    }

    @Override
    public void eat() {
        super.eat();
        food.eat();
    }
}

class FoodD2 extends Food2 {
    Food food;

    public FoodD2(Food food) {
        this.food = food;
    }

    @Override
    public void eat() {
        super.eat();
        food.eat();
    }
}

